{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 课后作业"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "| 列表的方法 | Description | 使用方法 | 备注 |\n",
    "| ---------- | ----------- | ---------|------|\n",
    "| append    |增加元素，增加在列表的末尾 |示例1|   无     |\n",
    "| clear    | 清空列表     |示例2|清除列表中的所有元素|\n",
    "| copy     | 复制列表     |示例3|无|\n",
    "| count    |  统计某个元素在列表中出现的次数  |示例4| 输出结果是出现次数,而不是列表元素的个数  |\n",
    "| extend   |  扩展列表中某个元素| 示例5| 增加的是一个字符串中的具体元素|\n",
    "| index    | 从列表中找出某个值的索引位置 | 示例6|找到的索引位置为第一个匹配项|\n",
    "| insert   |将指定对象插入列表的指定位置|示例7|结果是插入在指定元素的前面|\n",
    "| pop     | 移除列表中的一个元素 |示例8|默认最后一个元素|\n",
    "| remove   | 将某个元素从列表中移除|示例9|只移除某个元素的第一个匹配项|\n",
    "| reverse  | 将列表中的元素进行反转   |示例10|对列表的元素进行反向排序|\n",
    "| sort   | 将列表中的元素进行排序|示例11|按首字母进行排序|\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "names =[\"Jack\",\"Alex\",\"Marry\",\"Jan\"] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-10-d443f8efea96>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-10-d443f8efea96>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    names.\u001b[0m\n\u001b[1;37m          ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "names."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. append(增加）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jane', 'Alex', 'Tom']\n"
     ]
    }
   ],
   "source": [
    "names.append(\"Tom\")\n",
    "print (names)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.clear（清空）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "names.clear()\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.copy（复制）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jane', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "name02 = names.copy()\n",
    "print(name02)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4.count（计数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "List =[\"Mike\",\"Mary\",\"Jane\",\"Alex\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "List.count(\"Mike\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "List.count(\"Mary\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5.extend（扩展）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "names.extend(\"Mike\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'M', 'i', 'k', 'e']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 6. index(索引)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Jack\",\"Mary\"]\n",
    "names.index(\"Mary\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.insert(插入)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jane', 'Alex', 'Bob', 'Tom']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\",\"Tom\"]\n",
    "names.insert(4,\"Bob\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 8.pop(移除)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jane']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "names.pop()\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 9.remove(移除)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Alex', 'Jane']"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\",\"Jane\"]\n",
    "names.remove(\"Jane\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 10.reverse(反向列表元素）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Jane', 'Mary', 'Mike']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\"]\n",
    "names.reverse()\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 11.sort（排序）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Jane', 'Mary', 'Mike', 'Tom']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jane\",\"Alex\",\"Tom\"]\n",
    "names.sort()\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
